-- ********************************************
-- * Copyright (c) 2012 TPV R&D Center Brazil *
-- * All Rights Reserved                      *
-- ********************************************

--- toolkit.component.Image

local Image = Box:new()

function Image:new(o)
   if (type(o) ~= 'table') then
      o = {}
   end

   local newImage = Box:new(o)

   newImage.parent = nil

   newImage.componentType = "Image"

   newImage.fileName = o.fileName or ''
   newImage.behavior = o.behavior or nil

   newImage.activated = {
      flipHorizontally = false,
      flipVertically = false,
      resizeWidth = 0,
      resizeHeight = 0,
      rotation = 0,
      opacity = 255
   }

   newImage.deactivated = {
      flipHorizontally = false,
      flipVertically = false,
      resizeWidth = 0,
      resizeHeight = 0,
      rotation = 0,
      opacity = 255
   }

   newImage.focused = {
      flipHorizontally = false,
      flipVertically = false,
      resizeWidth = 0,
      resizeHeight = 0,
      rotation = 0,
      opacity = 255
   }

   newImage.selected = {
      flipHorizontally = false,
      flipVertically = false,
      resizeWidth = 0,
      resizeHeight = 0,
      rotation = 0,
      opacity = 255
   }

   --generate an object
   setmetatable(newImage, self)
   self.__index = self

   return newImage
end

function Image:setActivated(o)
   if (type(o) == 'table') then
      self.activated.flipHorizontally = o.flipHorizontally or self.activated.flipHorizontally
      self.activated.flipVertically = o.flipVertically or self.activated.flipVertically
      self.activated.resizeWidth = o.resizeWidth or self.activated.resizeWidth
      self.activated.resizeHeight = o.resizeHeight or self.activated.resizeHeight
      self.activated.rotation = o.rotation or self.activated.rotation
      self.activated.opacity = o.opacity or self.activated.opacity
   end
end

function Image:setDeactivated(o)
   if (type(o) == 'table') then
      self.deactivated.flipHorizontally = o.flipHorizontally or self.deactivated.flipHorizontally
      self.deactivated.flipVertically = o.flipVertically or self.deactivated.flipVertically
      self.deactivated.resizeWidth = o.resizeWidth or self.deactivated.resizeWidth
      self.deactivated.resizeHeight = o.resizeHeight or self.deactivated.resizeHeight
      self.deactivated.rotation = o.rotation or self.deactivated.rotation
      self.deactivated.opacity = o.opacity or self.deactivated.opacity
   end
end

function Image:setFocused(o)
   if (type(o) == 'table') then
      self.focused.flipHorizontally = o.flipHorizontally or self.focused.flipHorizontally
      self.focused.flipVertically = o.flipVertically or self.focused.flipVertically
      self.focused.resizeWidth = o.resizeWidth or self.focused.resizeWidth
      self.focused.resizeHeight = o.resizeHeight or self.focused.resizeHeight
      self.focused.rotation = o.rotation or self.focused.rotation
      self.focused.opacity = o.opacity or self.focused.opacity
   end
end

function Image:setSelected(o)
   if (type(o) == 'table') then
      self.selected.flipHorizontally = o.flipHorizontally or self.selected.flipHorizontally
      self.selected.flipVertically = o.flipVertically or self.selected.flipVertically
      self.selected.resizeWidth = o.resizeWidth or self.selected.resizeWidth
      self.selected.resizeHeight = o.resizeHeight or self.selected.resizeHeight
      self.selected.rotation = o.rotation or self.selected.rotation
      self.selected.opacity = o.opacity or self.selected.opacity
   end
end

function Image:setFileName(o)
   if (type(o) == 'string') then
      self.fileName = o
   end
end

function Image:redraw(o)
   self.parent:update(self)
end

return Image
